'use strict';


angular.module('app').controller('exportDataController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal',
    function($rootScope, $scope, $http, $state,toaster,$modal) {

        $scope.title = '数据导入导出';

        $scope.time;
        $scope.param={};
        $scope.submitBtn = true;
        $scope.codeNotpass = false;
        $scope.upload = false;

        var pass = sessionStorage.getItem('pass');
        if(pass){
//		console.log(pass);
            $scope.pass = false;
        }else{
            $scope.pass = true;
        }
        //获取用户手机号码
        $scope.userPhone = function(){
            $scope.phone = '手机号码获取中...';
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : 'dac/userManager/queryUser',
                data: angular.toJson($scope.param)
            }).then(function(result){
                $scope.loading = false;
                if(result.httpCode ==200){//成功
                    $scope.phone = result.data.phone_;
                    $scope.$apply();
                }else{
                    $scope.phone = '';
                    toaster.clear('*');
                    toaster.pop('error', '', result.msg);
                }
            });

        };
        $scope.userPhone();

        $scope.getSmsCode = function (phone) {

            $scope.record = {};
            $scope.record.phone =  phone;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/user/forgetPassword/getSmsCode',
                data: angular.toJson($scope.record)
            }).then(function (result) {
                $scope.loading = false;
                if (result.httpCode == 200) {
                    toaster.clear('*');
                    toaster.pop('success', '', "验证码已发送，请注意接收！");
                    var obj = $('#getCode');
                    var countdown=60;
                    settime(obj,countdown,phone);
                } else {
                    toaster.clear('*');
                    toaster.pop('error', '', result.msg);
                }
                $scope.$apply();
            });
        }

        //验证码倒计时
        function settime(obj,countdown,phone) {
            if (countdown == 0) {
                obj.removeAttr("disabled");
                obj.html("获取验证码");
                countdown = 60;
                return;
            } else {
                obj.html("重新发送" + countdown);
                obj.attr("disabled", true);
                countdown--;
            }
            setTimeout(function() {
                settime(obj,countdown)
            },1000)
        }

        //输入状态交互
        var phoneNumber = document.getElementById('phoneNumber');
        var phoneCode = document.getElementById('phoneCode');
        $scope.check = function(){
            var number = phoneNumber.value;
            var code = phoneCode.value;
            //console.log(code);
            (code.length==6)? $scope.submitBtn = false:$scope.submitBtn = true;
            (code.length>0)? $scope.codeNotpass = false:$scope.codeNotpass = true;
        }

        //首次打开页面验证身份
        $scope.test = function(){
            $scope.submitBtn = true
            $scope.number = phoneNumber.value;
            $scope.code = phoneCode.value;
            $scope.param = {
                phone:$scope.number,
                smsCode:$scope.code
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : 'dac/userManager/identifyingCode',
                data: angular.toJson($scope.param)
            }).then(function(result){
                console.log(result);
                if(result.httpCode ==200){//成功
                    toaster.clear('*');
                    toaster.pop('success','','验证成功！');
                    $scope.pass = false;//隐藏弹层
                    $scope.$apply();
                    var ss = sessionStorage.setItem('pass',$scope.pass);
                }else{
                    $scope.codeNotpass = true;
                    phoneCode.value = '';
                    $scope.$apply();
                }
            });
        };

    } ]);